package cn.stylefeng.roses.kernel.saas.factory;

import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.file.api.constants.FileConstants;
import cn.stylefeng.roses.kernel.rule.enums.SexEnum;
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.saas.entity.SysTenant;
import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUser;

/**
 * 租户的用户新增
 *
 * @author fengshuonan
 * @date 2021/5/26 22:54
 */
public class TenantUserFactory {

    /**
     * 通过租户信息，创建租户的超级管理员
     *
     * @author fengshuonan
     * @date 2021/5/26 22:56
     */
    public static SysUser createSysUser(SysTenant sysTenant) {
        SysUser sysUser = new SysUser();
        sysUser.setEmail(sysTenant.getEmail());
        sysUser.setPhone(sysTenant.getSafePhone());
        sysUser.setAccount(sysTenant.getSafePhone());
        sysUser.setSex(SexEnum.M.getCode());

        if (ObjectUtil.isEmpty(sysTenant.getCompanyLogo())) {
            sysUser.setAvatar(FileConstants.DEFAULT_AVATAR_FILE_ID);
        } else {
            sysUser.setAvatar(sysTenant.getCompanyLogo());
        }

        sysUser.setPassword(sysTenant.getPassword());
        sysUser.setRealName(sysTenant.getCompanyName());
        sysUser.setNickName(sysTenant.getCompanyName());
        sysUser.setSuperAdminFlag(YesOrNotEnum.Y.getCode());
        sysUser.setStatusFlag(StatusEnum.ENABLE.getCode());
        sysUser.setDelFlag(YesOrNotEnum.N.getCode());
        return sysUser;
    }

}
